package com.neighbor.neighborhooduser.controller;

import com.neighbor.neighborhooduser.service.IItemCollectionsService;
import com.neighbor.neighborhooduser.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 物品收藏记录表 前端控制器
 * </p>
 *
 * @author song
 * @since 2025-09-22 09:13:04
 */
@RestController
@RequestMapping("/itemCollections")
public class ItemCollectionsController {
    @Autowired
    private IItemCollectionsService iItemCollectionsService;
    //查看用户是否已收藏该物品
    @RequestMapping("/isCollect/{userId}/{itemId}")
    ResponseMsg isCollect(@PathVariable Integer userId,@PathVariable Integer itemId){
        if(iItemCollectionsService.isCollect(userId,itemId)==1){
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS,"true");
        }
        return ResponseMsg.getInstance(ResponseMsg.PERMISSIONS_ERROR,"false");
    }
    //收藏
    @RequestMapping("/collect/{userId}/{itemId}")
    ResponseMsg collect(@PathVariable Integer userId,@PathVariable Integer itemId){
        if (iItemCollectionsService.collect(userId,itemId)==1) {
            return ResponseMsg.success();
        }
        return ResponseMsg.getInstance(ResponseMsg.DATA_ERROR, "错误");
    }
    //取消收藏
    @RequestMapping("/unCollect/{userId}/{itemId}")
    ResponseMsg unCollect(@PathVariable Integer userId,@PathVariable Integer itemId){
        if (iItemCollectionsService.unCollect(userId,itemId)==1) {
            return ResponseMsg.success();
        }
        return ResponseMsg.getInstance(ResponseMsg.DATA_ERROR, "错误");
    }

    //查看用户收藏的所有物品,通过用户ID
    @RequestMapping("/getCollectionsById/{userId}")
    ResponseMsg getCollections(@PathVariable Integer userId){
        return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "获取收藏列表成功",
                iItemCollectionsService.getCollectionsById(userId));
    }


}
